﻿<template>
    <div class="UsingWireropeKeepDetail">
        <MyDialog :model-value="true" :type="DialogType.C3" :title="title" @close="onClose">
            <el-form ref="UsingWireropeKeepDetailFormRef" label-width="100" :model="thisData" :rules="rules">
                <div class="rowTitle marb-10">在用绳信息</div>
                <el-row>
                    <el-col :span="8">
                        <el-form-item label="在用绳编码" prop="code">
                            <el-input v-model="thisData.code" :disabled="true" maxlength="50">
                                <template #append v-if="!isSee">
                                    <el-button @click="onOpenWireropeSelect">
                                        <el-icon>
                                            <Search />
                                        </el-icon>
                                    </el-button>
                                </template>
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="在用绳名称" prop="name">
                            <el-input v-model="usingWireropeModel.name" maxlength="200" :disabled="true"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="规格型号" prop="guiGe">
                            <el-input v-model="usingWireropeModel.guiGe" maxlength="200" :disabled="true"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="8">
                        <el-form-item label="直径" prop="diameter">
                            <InputNumber v-model="usingWireropeModel.diameter" :disabled="true" append="mm"></InputNumber>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="公称捻距" prop="nianJu">
                            <InputNumber v-model="usingWireropeModel.nianJu" :disabled="true" append="mm"> </InputNumber>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="长度" prop="lengthNum">
                            <InputNumber v-model="usingWireropeModel.lengthNum" :disabled="true"></InputNumber>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="8">
                        <el-form-item label="绳子条数" prop="cnt">
                            <InputNumber v-model="usingWireropeModel.cnt" :precision="0" :disabled="true"></InputNumber>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="抗拉强度" prop="mpaID">
                            <DataSelect table="Mpa" class="w-100" v-model:id="usingWireropeModel.mpaID" v-model:name="usingWireropeModel.mpaName" :disabled="true"></DataSelect>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="表面状态" prop="surfaceStatusID">
                            <DataSelect table="SurfaceStatus" class="w-100" v-model:id="usingWireropeModel.surfaceStatusID" v-model:name="usingWireropeModel.surfaceStatusName" :disabled="true"></DataSelect>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="8">
                        <el-form-item label="捻制类型" prop="twistingTypeID">
                            <DataSelect table="TwistingType" class="w-100" v-model:id="usingWireropeModel.twistingTypeID" v-model:name="usingWireropeModel.twistingTypeName" :disabled="true"></DataSelect>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="矿山" prop="departmentID">
                            <DataSelect table="Department" class="w-100" :filter="{ _Type: Enums.Department_Type.矿山 }" v-model:id="usingWireropeModel.departmentID" :disabled="true"></DataSelect>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="安装日期" prop="installDate">
                            <el-date-picker class="w-100" v-model="usingWireropeModel.installDate" type="date" :disabled="true" />
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="8">
                        <el-form-item label="安装长度" prop="installLengthNum">
                            <InputNumber v-model="usingWireropeModel.installLengthNum" append="m" :disabled="true"></InputNumber>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="安装地点" prop="installAddressID">
                            <DataSelect table="InstallAddress" class="w-100" label="addressInfo" v-model:id="usingWireropeModel.installAddressID" v-model:name="usingWireropeModel.installAddressName" :disabled="true"></DataSelect>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="提升机类型" prop="hoisterID">
                            <DataSelect table="Hoister" class="w-100" v-model:id="usingWireropeModel.hoisterID" v-model:name="usingWireropeModel.hoisterName" :disabled="true"></DataSelect>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="8">
                        <el-form-item label="提升机用途" prop="hoisterUsageID">
                            <DataSelect ref="HoisterUsageRef" table="HoisterUsage" class="w-100" v-model:id="usingWireropeModel.hoisterUsageID" v-model:name="usingWireropeModel.hoisterUsageName" :disabled="true"></DataSelect>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="钢丝绳类型" prop="wireropeTypeID">
                            <DataSelect ref="WireropeTypeRef" table="WireropeType" class="w-100" v-model:id="usingWireropeModel.wireropeTypeID" v-model:name="usingWireropeModel.wireropeTypeName" :disabled="true"></DataSelect>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="主要负责人" prop="linkUser">
                            <el-input v-model="usingWireropeModel.linkUser" maxlength="50" :disabled="true"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="8">
                        <el-form-item label="负责人电话" prop="linkPhone">
                            <el-input v-model="usingWireropeModel.linkPhone" maxlength="20" :disabled="true"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="16">
                        <el-form-item label="备注" prop="remark">
                            <el-input v-model="usingWireropeModel.remark" maxlength="500" :disabled="true"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <div class="rowTitle marb-10">维保信息</div>

                <el-row>
                    <el-col :span="8">
                        <el-form-item label="维保类型" prop="wireropeKeepTypeID">
                            <DataSelect table="WireropeKeepType" class="w-100" v-model:id="thisData.wireropeKeepTypeID" v-model:name="thisData.wireropeKeepTypeName" :disabled="isSee"></DataSelect>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="实施对象" prop="doPosition">
                            <el-input v-model="thisData.doPosition" maxlength="200" :disabled="isSee"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="实施部门" prop="companyName">
                            <el-input v-model="thisData.companyName" maxlength="200" :disabled="isSee"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="8">
                        <el-form-item label="实施人员" prop="userName">
                            <el-input v-model="thisData.userName" maxlength="50" :disabled="isSee"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="实施日期" prop="doDate">
                            <el-date-picker class="w-100" v-model="thisData.doDate" type="date" :disabled="isSee" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="实施备注" prop="remark">
                            <el-input v-model="thisData.remark" maxlength="500" :disabled="isSee"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="8">
                        <el-form-item label="实施照片" prop="pic_Imgs">
                            <MyUpload v-model="thisData.pic_ImgsList" :disabled="isSee"></MyUpload>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="附件" prop="attr_Files">
                            <MyUpload v-model="thisData.attr_FilesList" :disabled="isSee"></MyUpload>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8"> </el-col>
                </el-row>
            </el-form>
            <UsingWireropeSelect v-if="isShowUsingWireropeSelect" :hasCheckbox="false" :hasRadio="true" @close="onCloseUsingWireropeSelect"></UsingWireropeSelect>

            <template #footer>
                <el-button type="primary" :loading="loading" @click="onSave" v-if="!isSee">保存</el-button>
            </template>
        </MyDialog>
    </div>
</template>

<script lang="ts" setup>
import Enums from "@/gx/Enums";
import Gx from "@/gx/Gx";
import { FormRules } from "element-plus";
import { DialogType } from "@/_gx/TsEnums";
import { tokenStore } from "@/stores/tokenStore";
import UsingWireropeSelect from "@/views/wi/UsingWirerope/UsingWireropeSelect.vue";
const store = tokenStore();

//接收父组件的传值
const rowAutoID = inject("rowAutoID") as Ref<number | null>;

//定义当前页面数据对象
const thisData = ref<any>({});
const usingWireropeModel = ref<any>({});

//查看
const isSee = ref(false);
//loading...
const loading = ref(false);

//定义表单验证规则
const rules = ref<FormRules>({
    code: [{ required: true, message: "请选择在用绳编码", trigger: "change" }],
    wireropeKeepTypeID: [{ required: true, message: "请选择维保类型", trigger: "change" }],
    doDate: [{ required: true, message: "请选择实施日期", trigger: "change" }],
});

//标题
const title = computed(() => {
    if (Gx.IsEmpty(rowAutoID.value)) {
        return "在用绳维保详情 - 创建";
    } else {
        return `在用绳维保详情 - 编辑 - ${usingWireropeModel.value.name}`;
    }
});

//初始化
const Init = (flag) => {
    if (flag) {
        isSee.value = true;
    }
    if (!Gx.IsEmpty(rowAutoID.value)) {
        App.CallApi(Api.UsingWireropeKeep.GetByID(rowAutoID.value), {
            success: (res) => {
                thisData.value = res;
                thisData.value.code = res.usingWireropeModel.code;
                usingWireropeModel.value = res.usingWireropeModel;
            },
        });
    } else {
        thisData.value.userName = store.me.name;
        thisData.value.doDate = Gx.FormatDate("YYYY-MM-DD");
        thisData.value.pic_ImgsList = [];
        thisData.value.attr_FilesList = [];
    }
};

//表单Ref对象
const UsingWireropeKeepDetailFormRef = ref(null);

//保存
const onSave = () => {
    UsingWireropeKeepDetailFormRef.value.validate((isOk: boolean) => {
        if (!isOk) {
            return;
        }

        let _api = null;
        let _data = thisData.value;
        if (Gx.IsEmpty(rowAutoID.value)) {
            //添加
            _api = Api.UsingWireropeKeep.Insert;
        } else {
            //修改
            _api = Api.UsingWireropeKeep.Update;
        }

        loading.value = true;
        App.CallApi(_api, {
            data: _data,
            success: (res) => {
                emits("close", true);
            },
            complete: () => {
                loading.value = false;
            },
        });
    });
};

/********************************************** 钢丝绳选择 **********************************************/

// 再用绳选择
let isShowUsingWireropeSelect = ref(false);

//打开钢丝绳选择
const onOpenWireropeSelect = () => {
    if (!isSee.value) {
        isShowUsingWireropeSelect.value = true;
    }
};

//关闭再用绳选择
const onCloseUsingWireropeSelect = (selectData) => {
    isShowUsingWireropeSelect.value = false;
    if (!Gx.IsEmpty(selectData)) {
        thisData.value.usingWireropeID = selectData.autoID;
        thisData.value.code = selectData.code;
        usingWireropeModel.value = selectData;
    }
};

//关闭
const onClose = () => {
    emits("close", false);
};

//向上抛出的事件与方法
const emits = defineEmits(["close"]);
defineExpose({ Init });
</script>
